<template>
    <van-sticky>
        <van-nav-bar title="分类" left-text="返回" left-arrow @click-left="onClickLeft" />
    </van-sticky>
    <div class="box">
        <div class="left">
            <van-sidebar v-model="active">
                <van-sidebar-item v-for="item in fenleiList" :title="item.cat_name" />
            </van-sidebar>

        </div>
        <div class="right">
            <van-grid :column-num="3" v-for="item in fenleiList[active]?.children">
                <van-grid-item v-for="value in item.children" :key="value.cat_id" :icon="value.cat_icon" 
                :text="value.cat_name" @click="goods(value.cat_id)" />
            </van-grid>
        </div>
    </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from 'vue-router'
const router = useRouter();
import { useFenleiStore } from '../../store'
import { storeToRefs } from 'pinia'
const { fenleiList } = storeToRefs(useFenleiStore());
const { FENLEI } = useFenleiStore();
FENLEI()
const active = ref(0)
const onClickLeft = () => history.back();

const goods=(cid)=>{
    router.push({
        path:'/Goods',
        query:{
            cid
        }
    })
}
</script>

<style lang="scss" scoped>
.box{
    display: flex;
}
.left{
    width: 100px;
}
.right{
    flex: 1;
}
</style>